﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WindowsFormsView;
using WindowsFormsModel.BusinessObjects;

namespace WindowsFormsPresenter.Unit
{
    public class UnitPresenter : Presenter<IUnitView>
    {
        public UnitPresenter(IUnitView view)
            : base(view)
        {
        }

        public void Display(string unitId)
        {
            if (unitId == null) return;

            var unit = Model.GetUnit(unitId);

            View.UnitID = unit.UnitID;
            View.UnitCode = unit.UnitCode;
            View.UnitName = unit.UnitName;
            View.RestaurantID = unit.RestaurantID;
            View.Description = unit.Description;
            View.IsActive = unit.IsActive;
        }

        public int Save()
        {
            var unit = new UnitModel
            {
                UnitID = View.UnitID,
                UnitCode = View.UnitCode,
                UnitName = View.UnitName,
                RestaurantID = View.RestaurantID,
                Description = View.Description,
                IsActive = View.IsActive
            };

            if (View.UnitID == null)
                return Model.AddUnit(unit);
            else
                return Model.UpdateUnit(unit);
        }

        public int Delete(string unitId)
        {
            return Model.DeleteUnit(unitId);
        }
    }
}
